<?php

namespace app\shop\controller;

use think\Request;
use think\Exception;
use think\Db;
use app\shop\model\ClientDocumentary as ClientDocumentaryModel;

class ClientDocumentary extends \ShopController{

    //跟单列表
    public function index(Request $request){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $params = $request->get();
            $data = $documentaryModel->search($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //跟单列表
    public function stage(Request $request){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $data = $documentaryModel->stage();
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //添加跟单
    public function add(Request $request){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $params = $request->post();
            $data = $documentaryModel->add($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //修改跟单
    public function edit(Request $request){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $params = $request->post();
            $data = $documentaryModel->edit($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //客户详情跟单列表
    public function easyDocumentary($id){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $data = $documentaryModel->easyDocumentary($id);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //删除跟单
    public function del_documentary($id){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $data = $documentaryModel->del_documentary($id);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //跟单详情
    public function detail($id){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $data = $documentaryModel->detail($id);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //点赞
    public function likes($id){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $data = $documentaryModel->likes($id);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //评论
    public function comment(Request $request){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $params = $request->post();
            $data = $documentaryModel->comment($params);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //删除评论
    public function delComment($id){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $data = $documentaryModel->delComment($id);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //批量删除跟单
    public function batchDel(Request $request){
        $documentaryModel = new ClientDocumentaryModel();
        try {
            $params = $request->post();
            $data = $documentaryModel->batchDel($params['documentary']);
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
    }

    //全部删除跟单
    public function delAll(){

        set_time_limit(0);

        $documentaryModel = new ClientDocumentaryModel();
        try {
            $data = $documentaryModel->delAll();
            $this->successTerminate($data);
        } catch (Exception $e) {
            $this->serverErrorTerminate($e->getMessage());
        }
        
    }

}